home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C12 / Simpcopy.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  820 b   |  39 lines

  1. //: C12:Simpcopy.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Simple operator=()
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. class Value {
  11.   int a, b;
  12.   float c;
  13. public:
  14.   Value(int aa = 0, int bb = 0, float cc = 0.0) {
  15.     a = aa;
  16.     b = bb;
  17.     c = cc;
  18.   }
  19.   Value& operator=(const Value& rv) {
  20.     a = rv.a;
  21.     b = rv.b;
  22.     c = rv.c;
  23.     return *this;
  24.   }
  25.   friend ostream&
  26.     operator<<(ostream& os, const Value& rv) {
  27.       return os << "a = " << rv.a << ", b = "
  28.         << rv.b << ", c = " << rv.c;
  29.     }
  30. };
  31.  
  32. int main() {
  33.   Value A, B(1, 2, 3.3);
  34.   cout << "A: " << A << endl;
  35.   cout << "B: " << B << endl;
  36.   A = B;
  37.   cout << "A after assignment: " << A << endl;
  38. } ///:~
  39.